import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';

import 'package:alice_screen/common/constant.dart';

//调用该类获取字符串内容
class MyLocalizations {
  final Map<String, Map<String, String>> localizedValues;
  final Locale locale;

  MyLocalizations(this.locale, this.localizedValues);
  static MyLocalizations of(BuildContext context) {
    return Localizations.of<MyLocalizations>(context, MyLocalizations);
  }

  String get flutterDemoHomePage {
    return localizedValues[locale.languageCode]['flutter_demo_home_page'];
  }

  String get scanToDownloadApp {
    return localizedValues[locale.languageCode]['scan_to_download_app'];
  }

  String get scanQrCode {
    return localizedValues[locale.languageCode]['scan_qr_code'];
  }

  String get deviceBinding {
    return localizedValues[locale.languageCode]['device_binding'];
  }

  String get distributionNetwork {
    return localizedValues[locale.languageCode]['distribution_network'];
  }

  String get appTopRightCorner {
    return localizedValues[locale.languageCode]['app_top_right_corner'];
  }

  String get click {
    return localizedValues[locale.languageCode]['click'];
  }

  String get addDevice {
    return localizedValues[locale.languageCode]['add_device'];
  }

  String get clickCorrespondingVersion {
    return localizedValues[locale.languageCode]['click_corresponding_version'];
  }

  String get installAndRegister {
    return localizedValues[locale.languageCode]['install_and_register'];
  }
}

class MyLocalizationsDelegate extends LocalizationsDelegate<MyLocalizations> {
  Map<String, Map<String, String>> localizedValues;
  MyLocalizationsDelegate(this.localizedValues);
  @override
  bool isSupported(Locale locale) => Constant.languages.contains(locale.languageCode);

  @override
  Future<MyLocalizations> load(Locale locale) {
    return SynchronousFuture<MyLocalizations>(
        MyLocalizations(locale, localizedValues));
  }

  @override
  bool shouldReload(LocalizationsDelegate<MyLocalizations> old) {
    return false;
  }
}